//
//  ViewController.m
//  ChangeImageSize
//
//  Created by Burn on 2019/7/31.
//  Copyright © 2019 menksoft. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    UIImage *image = [self image:[UIImage imageNamed:@"launch.png"] byScalingToSize:CGSizeMake(1242, 2688)];
//    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    //    NSString *filePath = [[paths objectAtIndex:0]stringByAppendingPathComponent:@"Image.png"];[UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES];
    NSString *path = @"/Users/buren/Desktop/outPutImage";

    
    
    
    NSDictionary *dic = @{
                          @"Portrait iOS 12+ Max.png" : @(CGSizeMake(1242, 2688)),
                          @"Portrait iOS 12+ XR.png" : @(CGSizeMake(828, 1792)),
                          @"Portrait iOS 11+ X Xs.png" : @(CGSizeMake(1125, 2436)),
                          @"Portrait iOS 8+ 5.5.png" : @(CGSizeMake(1242, 2208)),
                          @"Portrait iOS 8+ 4.7.png" : @(CGSizeMake(750, 1334)),
                          @"Portrait iOS 7+ 2X.png" : @(CGSizeMake(640, 960)),
                          @"Portrait iOS 7+ Retina4.png" : @(CGSizeMake(640, 1136)),
                          @"Portrait iOS 5,6,1.png" : @(CGSizeMake(320, 480)),
                          @"Portrait iOS 5,6,2.png" : @(CGSizeMake(640, 960)),
                          @"Portrait iOS 5,6,3.png" : @(CGSizeMake(640, 1136)),
                          };
    
    
    
    for (int i = 0; i < dic.allKeys.count; i++) {
        UIImage *image = [self image:[UIImage imageNamed:@"launch.png"] byScalingToSize:[dic[dic.allKeys[i]]CGSizeValue]];
        NSString *filePath = [path stringByAppendingPathComponent:dic.allKeys[i]];[UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES];
        BOOL result = [UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES];
        if (result) {
            NSLog(@"%@输出成功",dic.allKeys[i]);
        }else{
            NSLog(@"%@---输出失败",dic.allKeys[i]);
        }
        if (i == dic.allKeys.count-1) {
            NSLog(@"输入完事儿👏");
        }
    }
    
}


- (UIImage *)image:(UIImage*)image byScalingToSize:(CGSize)targetSize {
    UIImage *sourceImage = image;
    UIImage *newImage = nil;
    
    UIGraphicsBeginImageContext(targetSize);
    
    CGRect thumbnailRect = CGRectZero;
    thumbnailRect.origin = CGPointZero;
    thumbnailRect.size.width  = targetSize.width;
    thumbnailRect.size.height = targetSize.height;
    
    [sourceImage drawInRect:thumbnailRect];
    
    newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return newImage ;
}

@end
